package com.hy.mydesktop.client.mvc.grid;

import java.util.Iterator;

import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.widget.Component;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.google.gwt.user.client.ui.Widget;
import com.hy.mydesktop.client.component.type.ComponentTypeEnum;
import com.hy.mydesktop.client.mvc.base.BaseDisplay;
import com.hy.mydesktop.client.mvc.grid.GridSetModulesController.IGridSetModulesDiplay;
import com.hy.mydesktop.shared.util.log.MyLoggerUtil;



public class GridSetModuleDiplay  implements IGridSetModulesDiplay{

	private GridSetModule gridSetModule=null;
	private Grid<ModelData> grid=null;
	public GridSetModuleDiplay(GridSetModule gridSetModule) {
		this.gridSetModule=gridSetModule;
	}
	@Override
	public boolean add(Widget widget) {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public Component getComponent() {
		
		return gridSetModule;
	}
	@Override
	public void setComponent(Component component) {
		this.gridSetModule=(GridSetModule)component;
	}
	@Override
	public Widget asWidget() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public Grid<ModelData> getGrid() {
		//FormPanel formPanel = (FormPanel)c.getItems().get(2);
		//以下的，才和grid有关
//		ContentPanel	gridPanel = (ContentPanel)formPanel.getItems().get(0);
		ContentPanel	gridPanel = gridSetModule;
		for(Iterator<Component> it = gridPanel.iterator(); it.hasNext(); ) {
				
				LayoutContainer layoutContainer = (LayoutContainer)it.next();
				for(Iterator<Component> subIt = layoutContainer.iterator(); subIt.hasNext(); ) {					
					Component subComponent = subIt.next();
					if (subComponent instanceof Grid) {
						grid = (Grid<ModelData>)subComponent;
					}
					
				} 								
		} 
		if (grid==null) {
			MyLoggerUtil.printError(GridSetModuleDiplay.class, "gridSetModule 的 gird为空！");
			throw new RuntimeException("gridSetModule 的 gird为空！ ");
		}
		
		return grid;
	}
	
	@Override
	public ComponentTypeEnum getGridModuleType() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public GridSetModule getGridSetModule() {
		return gridSetModule;
	}

	

}
